package com.example.oasystem.dao.notice;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.oasystem.entity.notice.AoaNoticeListOfChen;
import com.example.oasystem.entity.notice.AoaNoticeUserRelation;
import com.example.oasystem.entity.notice.NoticeDTO;
import com.example.oasystem.entity.user.AoaUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AoaNoticeListDao extends BaseMapper<AoaNoticeListOfChen> {
    List<NoticeDTO> findNotice2(int userId, String baseKey);
    //查找直系下属
    @Select("select * from aoa_user where father_id = #{userId}")
    List<AoaUser> selectSonUser(int userId);
    //根据noticeId在relation表中查询数据记录
    @Select("select * from aoa_notice_user_relation where relatin_notice_id=#{noticeId} ")
    List<AoaNoticeUserRelation> findRelationByNoticeId(int noticeId);

    AoaNoticeListOfChen selectNotice(int id);

    @Update("update aoa_notice_user_relation set is_read=1 where relatin_notice_id=#{noticeId} and relatin_user_id=#{uid}")
    int updateRead(int noticeId, int uid);
    @Update("update aoa_notice_user_relation set is_read=1 where relatin_id=#{id}")
    int updateReadByRelation(int id);
    @Delete("delete from aoa_notice_user_relation where relatin_id=#{id}")
    int deleteRelatioByRelationId(int id);
    //添加noticerelation表
    @Insert("insert into aoa_notice_user_relation(is_read,relatin_notice_id,relatin_user_id) values (0,#{noticeId},#{uid})")
    int insertNoticeRelation(int noticeId, int uid);

}